<?php
/**
 *
 */
namespace Dclub\modules\Catalog;

class Model_Detail
    extends \Yz\modules\Generic\Model_Default
{


    /**
     *  a name of item class (Yz_Item_Interface)
     *  @var string
     */
    protected $itemName = false;


    /************************************
     *      Public methods
     ************************************/

    /** determine the correct item class from item's category id and load the complete item
     *  @param int itemId
     *  @return Item_XXX
     */
    public function fetchTypedItemById($itemId)
    {
        debug();
        $model = $this->module->selectModel("TreePath");
        $itemPath = new \Yz_Array($model->fetchItemPath($itemId));
        $type = $itemPath[0]->name;

        $this->selectItem($type);
        $item = $this->fetchItemById($itemId);
        $item->setCatPath($itemPath);
        return $item;
    }

    /************************************
     *      Protected methods
     ************************************/



    protected function describeSource()
    {
        debug();
        static $f0Name;
        $out = parent::describeSource();
        if (null === $f0Name) {
            $f0Name = $out->f0->name . '_spec_' . strtolower($this->itemName);
        }
        $out->f0->name = $f0Name;
        return $out;
    }

}
